<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blogs/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blogs/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blogs/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blogs/images/apple-touch-icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/blogs/images/favicon-32x32.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/blogs/images/favicon-16x16.png?v=5.1.3">


  <link rel="mask-icon" href="/blogs/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="Vue," />










<meta name="description" content="写在前面阅读了本文？你能了解到什么？ vue是如何被创建的？ vue是如何处理数据的？ vue是如何感知事件和处理事件的？ 为后续了解双向绑定大侠基础  1.Vue页面构成？ 首先，我们都知道Vue其实更准确来说，他是一个库，在Vue中，vue规定了很多方法，也有很多写法，大大的简化了我们在WEB网页中对DOM元素的复杂的操作。极大的提升了开发效率。我们首先来看一个Vue的页面结构。  对于一个V">
<meta property="og:type" content="article">
<meta property="og:title" content="手撕vue之对事件挂载原理详解">
<meta property="og:url" content="https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/index.html">
<meta property="og:site_name" content="Chao&#39;s blog">
<meta property="og:description" content="写在前面阅读了本文？你能了解到什么？ vue是如何被创建的？ vue是如何处理数据的？ vue是如何感知事件和处理事件的？ 为后续了解双向绑定大侠基础  1.Vue页面构成？ 首先，我们都知道Vue其实更准确来说，他是一个库，在Vue中，vue规定了很多方法，也有很多写法，大大的简化了我们在WEB网页中对DOM元素的复杂的操作。极大的提升了开发效率。我们首先来看一个Vue的页面结构。  对于一个V">
<meta property="og:locale">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_1.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_2.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_3.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_4.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_5.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_6.png">
<meta property="article:published_time" content="2022-03-17T10:55:43.000Z">
<meta property="article:modified_time" content="2022-03-20T14:11:14.689Z">
<meta property="article:author" content="Chaoyxy">
<meta property="article:tag" content="Vue">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://louchaoyy.gitee.io/blogs/2022/03/17/手撕vue之对事件挂载和双向绑定原理详解/"/>





  <title>手撕vue之对事件挂载原理详解 | Chao's blog</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blogs/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Chao's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blogs/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blogs/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blogs/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://louchaoyy.gitee.io/blogs/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blogs/images/cat.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Chao's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">手撕vue之对事件挂载原理详解</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2022-03-17T18:55:43+08:00">
                2022-03-17
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2022/03/17/手撕vue之对事件挂载和双向绑定原理详解/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2><h3 id="阅读了本文？你能了解到什么？"><a href="#阅读了本文？你能了解到什么？" class="headerlink" title="阅读了本文？你能了解到什么？"></a>阅读了本文？你能了解到什么？</h3><ul>
<li>vue是如何被创建的？</li>
<li>vue是如何处理数据的？</li>
<li>vue是如何感知事件和处理事件的？</li>
<li>为后续了解双向绑定大侠基础</li>
</ul>
<h2 id="1-Vue页面构成？"><a href="#1-Vue页面构成？" class="headerlink" title="1.Vue页面构成？"></a>1.Vue页面构成？</h2><ul>
<li><p>首先，我们都知道Vue其实更准确来说，他是一个库，在Vue中，vue规定了很多方法，也有很多写法，大大的简化了我们在WEB网页中对DOM元素的复杂的操作。极大的提升了开发效率。我们首先来看一个Vue的页面结构。</p>
<ol>
<li><p>对于一个Vue单文件组件来说，他主要有三部分构成</p>
<ul>
<li><p>template部分，这里主要用于页面的渲染，对应于文档部分</p>
<p><template></template></p>
</li>
<li><p>script部分，这里写<strong>Js</strong>的逻辑层代码</p>
<script></script></li>
<li><p>style部分，主要是样式的填充</p>
<style></style></li>
</ul>
</li>
<li><p>对于一个Vue页面来说，我们只看vue逻辑部分，那么他是由以下几部分构成的</p>
<ul>
<li><code>el</code>节点</li>
<li>data区域：这里是vue数据定义的一个区域，所有的vue数据都从这里来</li>
<li>methods区；这里是大部分的方法都在这里定义，在这里使用</li>
<li>生命周期函数区：包括<code>beforeCreated,created,mounted,destroyed</code>等生命周期函数，这里不多做介绍。</li>
</ul>
</li>
</ol>
</li>
</ul>
<span id="more"></span>

<h2 id="2-Vue的创建"><a href="#2-Vue的创建" class="headerlink" title="2.Vue的创建"></a>2.Vue的创建</h2><ul>
<li><p>首先我们创建一个HTML文件，在里面引入我们自己定义的<code>vue.js</code>,注意：这个vue.js不是Vue官方的，是我们自己的，所以暂时不具备尤雨溪大神的那些功能</p>
</li>
<li><p>HTML文件如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>Vue事件挂载详解<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;app&quot;</span>&gt;</span></span><br><span class="line">    &#123;&#123;str&#125;&#125;</span><br><span class="line">    <span class="tag">&lt;<span class="name">h1</span>&gt;</span>&#123;&#123;str&#125;&#125;<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">&quot;btn&quot;</span>&gt;</span>按钮<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;vue.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="javascript"></span></span><br><span class="line"><span class="javascript">    <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="javascript">        <span class="attr">el</span>:<span class="string">&quot;#app&quot;</span>,  <span class="comment">//挂在在根节点上</span></span></span><br><span class="line"><span class="javascript">        <span class="attr">data</span>:&#123;</span></span><br><span class="line"><span class="javascript">            <span class="attr">str</span>:<span class="string">&quot;hello,张三&quot;</span>,</span></span><br><span class="line"><span class="javascript">            <span class="attr">num</span>:<span class="number">125</span></span></span><br><span class="line"><span class="javascript">        &#125;,</span></span><br><span class="line"><span class="javascript">        <span class="attr">methods</span>:&#123;</span></span><br><span class="line"><span class="javascript">          </span></span><br><span class="line"><span class="javascript">        &#125;</span></span><br><span class="line"><span class="javascript">    &#125;)</span></span><br><span class="line"><span class="javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>可以看到我们已经具备了一个框架了</p>
<p>下面引入vue.js的代码</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@name</span>:vue.js</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span>:louchao</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span>:2022/3/20 20:48</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Vue</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="title">constructor</span>(<span class="params">options</span>)</span> &#123;</span><br><span class="line">        <span class="built_in">console</span>.log(options)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>当我们打印这个options时，我们可以看到如下：</p>
<img src="/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_1.png" class title="options打印结果">

<p>首先，这个options是什么呢？</p>
<p>我们可以看到options是我们在构造函数里面传过来的，也就是vue实例传过来的对象（在HTML中的new Vue中传入的<code>&#123;&#125;</code>对象），也就是{}里面的内容。</p>
<p>我们打印this，也就是vue实例，此时我们得到一个空对象</p>
<img src="/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_2.png" class title="this打印结果"></li>
<li><p>此时我们想要让this上有东西，我们可以把options上的东西挂在到this大对象上</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Vue</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="title">constructor</span>(<span class="params">options</span>)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.$data = options.data</span><br><span class="line">        <span class="built_in">this</span>.$el = <span class="built_in">document</span>.querySelector(options.el)</span><br><span class="line">        <span class="built_in">this</span>.$options = options</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;options==&quot;</span>,options)</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;this==&quot;</span>,<span class="built_in">this</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<img src="/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_3.png" class title="把options上的属性挂载在this上"></li>
</ul>
<h2 id="3-编译解析DOM树"><a href="#3-编译解析DOM树" class="headerlink" title="3.编译解析DOM树"></a>3.编译解析DOM树</h2><ul>
<li><p>我们想要把整个el根节点的每个元素进行解析，从而拿到我们想要的插值表达式的内容</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//编译模板</span></span><br><span class="line">   <span class="function"><span class="title">compile</span>(<span class="params">node</span>)</span>&#123;</span><br><span class="line">       <span class="comment">//遍历根节点下的文本节点和元素节点</span></span><br><span class="line">       node.childNodes.forEach(<span class="function">(<span class="params">item,index</span>)=&gt;</span>&#123;</span><br><span class="line">           <span class="comment">//遍历出每一个节点</span></span><br><span class="line">           <span class="built_in">console</span>.log(<span class="string">&quot;item&quot;</span>,item)</span><br><span class="line">           <span class="built_in">console</span>.log(<span class="string">&quot;item.nodeType&quot;</span>,item.nodeType)</span><br><span class="line">       &#125;)</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<img src="/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_4.png" class title="遍历出每个子节点与其类型">

<p>由图可知，文本节点为<code>text</code>，对应的类型值为<code>nodeType==3</code>，相对应的元素节点则对应的类型值为<code>nodeType==1</code>,那么我们知道，我们的插值表达式都放在文本节点，因此我们要想去解析插值表达式，那么我们去找nodeType==3就可以</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//文本节点</span></span><br><span class="line"><span class="keyword">if</span> (item.nodeType == <span class="number">3</span>)&#123;</span><br><span class="line">    <span class="comment">//使用正则表达式来匹配&#123;&#123;xx&#125;&#125;里面的xxxx</span></span><br><span class="line">    <span class="keyword">let</span> reg = <span class="regexp">/\&#123;\&#123;(.*?)\&#125;\&#125;/g</span>;</span><br><span class="line">    <span class="keyword">let</span> text = item.textContent;</span><br><span class="line">    <span class="comment">//用vmkey把match替换掉</span></span><br><span class="line">    item.textContent = text.replace(reg,<span class="function">(<span class="params">match,vmkey</span>)=&gt;</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;match&quot;</span>,match);</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;vmkey&quot;</span>,vmkey);</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">this</span>.$data[vmkey];</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<img src="/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_5.png" class title="通过正则匹配把需要修改的值换掉"></li>
</ul>
<h2 id="4-事件感知和处理"><a href="#4-事件感知和处理" class="headerlink" title="4.事件感知和处理"></a>4.事件感知和处理</h2><ol>
<li>首先事件一定是存在于元素节点内，也就是在&lt;&gt;&lt;/&gt;等标签内，元素类型值为nodeType == 1,因此我们关注类型值为1的地方就好。</li>
<li>其次，我们要先判断该元素节点是否存在<code>@click</code>关键字作为的属性，要想感知事件,如果存在说明该元素存在事件，也就是methods方法，否则不存在。</li>
<li>最后，我们需要添加事件监听函数，对相应的函数做处理。</li>
</ol>
<ul>
<li><p>我们开始处理nodeType类型值为1的情况</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//元素节点</span></span><br><span class="line"><span class="keyword">if</span> (item.nodeType == <span class="number">1</span>)&#123;</span><br><span class="line">    <span class="comment">//判断是否存在点击事件</span></span><br><span class="line">    <span class="keyword">if</span> (item.hasAttribute(<span class="string">&quot;@click&quot;</span>))&#123;</span><br><span class="line">        <span class="keyword">let</span> vmkey = item.getAttribute(<span class="string">&quot;@click&quot;</span>).trim();</span><br><span class="line">        <span class="comment">//监听点击事件，让他干嘛就干嘛</span></span><br><span class="line">        addEventListener(<span class="string">&quot;click&quot;</span>,<span class="function">(<span class="params">event</span>)=&gt;</span>&#123;</span><br><span class="line">            <span class="built_in">this</span>.eventFn = <span class="built_in">this</span>.$options.methods[vmkey].bind(<span class="built_in">this</span>);</span><br><span class="line">            <span class="built_in">this</span>.eventFn(event)</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//递归遍历，直到为文本节点</span></span><br><span class="line">    <span class="keyword">if</span> (item.childNodes.length &gt; <span class="number">0</span>)&#123;</span><br><span class="line">        <span class="built_in">this</span>.compile(item)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>假如我们定义一个函数，每次点击，就打印”hahaha“以及vue实例，那在HTML中就是这样</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;app&quot;</span>&gt;</span></span><br><span class="line">    &#123;&#123;str&#125;&#125;</span><br><span class="line">    <span class="tag">&lt;<span class="name">h1</span>&gt;</span>&#123;&#123;str&#125;&#125;<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">&quot;btn&quot;</span>&gt;</span>按钮<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;vue_1.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="javascript"></span></span><br><span class="line"><span class="javascript">    <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="javascript">        <span class="attr">el</span>:<span class="string">&quot;#app&quot;</span>,  <span class="comment">//挂在在根节点上</span></span></span><br><span class="line"><span class="javascript">        <span class="attr">data</span>:&#123;</span></span><br><span class="line"><span class="javascript">            <span class="attr">str</span>:<span class="string">&quot;hello,张三&quot;</span>,</span></span><br><span class="line"><span class="javascript">            <span class="attr">num</span>:<span class="number">125</span></span></span><br><span class="line"><span class="javascript">        &#125;,</span></span><br><span class="line"><span class="javascript">        <span class="attr">methods</span>:&#123;</span></span><br><span class="line"><span class="javascript">            <span class="function"><span class="title">btn</span>(<span class="params">e</span>)</span>&#123;</span></span><br><span class="line"><span class="javascript">                <span class="built_in">console</span>.log(<span class="string">&quot;hahaha&quot;</span>)</span></span><br><span class="line"><span class="javascript">                <span class="built_in">console</span>.log(<span class="built_in">this</span>);</span></span><br><span class="line"><span class="javascript">            &#125;</span></span><br><span class="line"><span class="javascript">        &#125;</span></span><br><span class="line"><span class="javascript">    &#125;)</span></span><br><span class="line"><span class="javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
<li><p>在vue.js中我们这么处理</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@name</span>:vue.js</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span>:louchao</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span>:2022/3/20 20:48</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Vue</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="title">constructor</span>(<span class="params">options</span>)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.$data = options.data;</span><br><span class="line">        <span class="built_in">this</span>.$el = <span class="built_in">document</span>.querySelector(options.el);</span><br><span class="line">        <span class="built_in">this</span>.$options = options;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;options==&quot;</span>,options);</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;this==&quot;</span>,<span class="built_in">this</span>);</span><br><span class="line"></span><br><span class="line">        <span class="built_in">this</span>.compile(<span class="built_in">this</span>.$el);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//编译模板</span></span><br><span class="line">    <span class="function"><span class="title">compile</span>(<span class="params">node</span>)</span>&#123;</span><br><span class="line">        <span class="comment">//遍历根节点下的文本节点和元素节点</span></span><br><span class="line">        node.childNodes.forEach(<span class="function">(<span class="params">item,index</span>)=&gt;</span>&#123;</span><br><span class="line">            <span class="comment">//遍历出每一个节点</span></span><br><span class="line">            <span class="comment">//元素节点</span></span><br><span class="line">            <span class="comment">// console.log(&quot;item&quot;,item);</span></span><br><span class="line">            <span class="comment">// console.log(&quot;type&quot;,item.nodeType);</span></span><br><span class="line">            <span class="comment">//元素节点</span></span><br><span class="line">            <span class="keyword">if</span> (item.nodeType == <span class="number">1</span>)&#123;</span><br><span class="line">                <span class="comment">//判断是否存在点击事件</span></span><br><span class="line">                <span class="keyword">if</span> (item.hasAttribute(<span class="string">&quot;@click&quot;</span>))&#123;</span><br><span class="line">                    <span class="keyword">let</span> vmkey = item.getAttribute(<span class="string">&quot;@click&quot;</span>).trim();</span><br><span class="line">                    <span class="comment">//监听点击事件，让他干嘛就干嘛</span></span><br><span class="line">                    addEventListener(<span class="string">&quot;click&quot;</span>,<span class="function">(<span class="params">event</span>)=&gt;</span>&#123;</span><br><span class="line">                        <span class="built_in">this</span>.eventFn = <span class="built_in">this</span>.$options.methods[vmkey].bind(<span class="built_in">this</span>);</span><br><span class="line">                        <span class="built_in">this</span>.eventFn(event)</span><br><span class="line">                    &#125;)</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//递归遍历，直到为文本节点</span></span><br><span class="line">                <span class="keyword">if</span> (item.childNodes.length &gt; <span class="number">0</span>)&#123;</span><br><span class="line">                    <span class="built_in">this</span>.compile(item)</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//文本节点</span></span><br><span class="line">            <span class="keyword">if</span> (item.nodeType == <span class="number">3</span>)&#123;</span><br><span class="line">                <span class="comment">//使用正则表达式来匹配&#123;&#123;xx&#125;&#125;里面的xxxx</span></span><br><span class="line">                <span class="keyword">let</span> reg = <span class="regexp">/\&#123;\&#123;(.*?)\&#125;\&#125;/g</span>;</span><br><span class="line">                <span class="keyword">let</span> text = item.textContent;</span><br><span class="line">                <span class="comment">//用vmkey把match替换掉</span></span><br><span class="line">                item.textContent = text.replace(reg,<span class="function">(<span class="params">match,vmkey</span>)=&gt;</span>&#123;</span><br><span class="line">                    <span class="built_in">console</span>.log(<span class="string">&quot;match&quot;</span>,match);</span><br><span class="line">                    <span class="built_in">console</span>.log(<span class="string">&quot;vmkey&quot;</span>,vmkey);</span><br><span class="line">                    <span class="keyword">return</span> <span class="built_in">this</span>.$data[vmkey];</span><br><span class="line">                &#125;)</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>结果如下：</strong></p>
<img src="/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/vue_6.png" class title="事件处理结果"></li>
</ul>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="http://chaoyxy.cn/data/User/admin/home/desktop/images/alipay.jpg" alt=" 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="http://chaoyxy.cn/data/User/admin/home/desktop/images/wechatpay.jpg" alt=" 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blogs/tags/Vue/" rel="tag"># Vue</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blogs/2022/03/15/flutter%E5%9F%BA%E6%9C%AC%E7%BB%84%E4%BB%B6%E7%9A%84%E4%BD%BF%E7%94%A8/" rel="next" title="flutter基本组件的使用">
                <i class="fa fa-chevron-left"></i> flutter基本组件的使用
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blogs/2022/03/18/vue%E5%8F%8C%E5%90%91%E6%95%B0%E6%8D%AE%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%A7%A3%E6%9E%90/" rel="prev" title="vue双向数据绑定原理解析(源代码在文章末尾)">
                vue双向数据绑定原理解析(源代码在文章末尾) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a target="_blank" rel="noopener" href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blogs/images/cat.jpg"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blogs/archives">
              
                  <span class="site-state-item-count">43</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blogs/tags/index.html">
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/louchaoyy" target="_blank" title="Gitee">
                      
                        <i class="fa fa-fw fa-gitee"></i>Gitee</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="louchao@louchaoyy.cn" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%86%99%E5%9C%A8%E5%89%8D%E9%9D%A2"><span class="nav-number">1.</span> <span class="nav-text">写在前面</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%98%85%E8%AF%BB%E4%BA%86%E6%9C%AC%E6%96%87%EF%BC%9F%E4%BD%A0%E8%83%BD%E4%BA%86%E8%A7%A3%E5%88%B0%E4%BB%80%E4%B9%88%EF%BC%9F"><span class="nav-number">1.1.</span> <span class="nav-text">阅读了本文？你能了解到什么？</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-Vue%E9%A1%B5%E9%9D%A2%E6%9E%84%E6%88%90%EF%BC%9F"><span class="nav-number">2.</span> <span class="nav-text">1.Vue页面构成？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-Vue%E7%9A%84%E5%88%9B%E5%BB%BA"><span class="nav-number">3.</span> <span class="nav-text">2.Vue的创建</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E7%BC%96%E8%AF%91%E8%A7%A3%E6%9E%90DOM%E6%A0%91"><span class="nav-number">4.</span> <span class="nav-text">3.编译解析DOM树</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E4%BA%8B%E4%BB%B6%E6%84%9F%E7%9F%A5%E5%92%8C%E5%A4%84%E7%90%86"><span class="nav-number">5.</span> <span class="nav-text">4.事件感知和处理</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Chaoyxy</span>

  
</div>

<span id="busuanzi_container_site_pv">
    本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<!--

  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.3</div>
-->




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/blogs/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/blogs/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/blogs/js/src/motion.js?v=5.1.3"></script>



  
  


  <script type="text/javascript" src="/blogs/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/blogs/js/src/schemes/pisces.js?v=5.1.3"></script>



  
  <script type="text/javascript" src="/blogs/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/blogs/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/blogs/js/src/bootstrap.js?v=5.1.3"></script>



  


  

    
      <script id="dsq-count-scr" src="https://Chaoyxy.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'https://louchaoyy.gitee.io/blogs/2022/03/17/%E6%89%8B%E6%92%95vue%E4%B9%8B%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%8C%82%E8%BD%BD%E5%92%8C%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%AF%A6%E8%A7%A3/';
          this.page.identifier = '2022/03/17/手撕vue之对事件挂载和双向绑定原理详解/';
          this.page.title = '手撕vue之对事件挂载原理详解';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://Chaoyxy.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  





  

  

  

  
  

  

  

  

</body>
</html>
